define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/wrong/index' + location.search,
                    add_url: 'finance/wrong/add',
                    edit_url: 'finance/wrong/edit',
                    del_url: 'finance/wrong/del',
                    multi_url: 'finance/wrong/multi',
                    import_url: 'finance/wrong/import',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                showSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'open_id', title: __('Open_id'), operate: 'LIKE'},
                        // {field: 'session_key', title: __('Session_key'), operate: 'LIKE'},
                        // {field: 'group_id', title: __('Group_id')},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        // {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        // {field: 'password', title: __('Password'), operate: 'LIKE'},
                        // {field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        // {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3'),"4":__('Level 4'),"5":__('Level 5')}, formatter: Table.api.formatter.normal},
                        {field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"2":__('Gender 2'),"3":__('Gender 3')}, formatter: Table.api.formatter.normal, operate: false},
                        // {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'bio', title: __('Bio'), operate: 'LIKE'},
                        // {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        // {field: 'score', title: __('Score')},
                        // {field: 'successions', title: __('Successions')},
                        // {field: 'maxsuccessions', title: __('Maxsuccessions')},
                        // {field: 'prevtime', title: __('Prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'logintime', title: __('Logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
                        // {field: 'loginfailure', title: __('Loginfailure')},
                        // {field: 'joinip', title: __('Joinip'), operate: 'LIKE'},
                        // {field: 'jointime', title: __('Jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'token', title: __('Token'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {1: __('启用'), 2: __('禁用')}},
                        // {field: 'verification', title: __('Verification'), operate: 'LIKE'},
                        // {field: 'age', title: __('Age')},
                        // {field: 'number', title: __('Number'), operate: 'LIKE'},
                        // {field: 'company_id', title: __('Company_id')},
                        // {field: 'health', title: __('Health'), searchList: {"1":__('Health 1'),"2":__('Health 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'real', title: __('Real'), searchList: {"1":__('Real 1'),"2":__('Real 2')}, formatter: Table.api.formatter.normal},
                        // {field: 'work_hour', title: __('Work_hour')},
                        // {field: 'work_times', title: __('Work_times')},
                        {field: 'error_times', title: __('Error_times'), operate: false, sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'disable',
                                    text: __('禁用'),
                                    title: __('禁用'),
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    refresh: true,
                                    hidden: function (row, o) {
                                        if (row.status === 2) return true
                                    },
                                    confirm: '即将禁止该会员在平台报名和参加工作，请确认是否禁用！',
                                    url: 'user/user/disable',
                                    success: function (data) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                },
                                {
                                    name: 'enable',
                                    text: __('启用'),
                                    title: __('启用'),
                                    classname: 'btn btn-xs btn-success btn-ajax',
                                    refresh: true,
                                    hidden: function (row, o) {
                                        if (row.status === 1) return true
                                    },
                                    url: 'user/user/enable',
                                    success: function (data) {
                                        $(".btn-refresh").trigger("click");
                                    },
                                },
                            ]
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});